package br.com.fidalgotecnologia.layar.data;

import java.util.List;

import javax.persistence.EntityManager;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import br.com.fidalgotecnologia.core.data.abs.BaseDAO;
import br.com.fidalgotecnologia.layar.entity.Object;

public class ObjectDAO extends BaseDAO<Object> {
	private static ObjectDAO instance;
	public static ObjectDAO getInstance() {
		if(instance == null){
			instance = new ObjectDAO();
		}
		return instance;
	}
	@Override
	public Class<Object> getClasse() {
		// TODO Auto-generated method stub
		return Object.class;
	}
	public Object buscarObject(Object object) {
		Object retorno = null;
		try {
			beginUserTransaction();
		
		EntityManager em = getEntityManager();
	    Session session = (Session)em.getDelegate();
	    session.beginTransaction();
	    Criteria criteria = session.createCriteria(getClasse());
	    criteria.add(Restrictions.eq("id", object.getId()));
	    retorno = (Object)criteria.uniqueResult();
	    session.getTransaction().commit();
	    commitUserTransaction();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    return retorno;
	}

}
